<?php

/**
 * The template for displaying comments
 *
 * This is the template that displays the area of the page that contains both the current comments
 * and the comment form.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Wordkit
 */

/*
 * If the current post is protected by a password and
 * the visitor has not yet entered the password we will
 * return early without loading the comments.
 */
if (post_password_required()) {
	return;
}
?>

<div id="comments" class="uk-comment uk-section">

	<?php
	// You can start editing here -- including this comment!
	if (have_comments()) :
	?>
		<h4 class="uk-comments-title uk-margin">
			<?php
			$wordkit_comment_count = get_comments_number();
			if ('1' === $wordkit_comment_count) {
				printf(
					/* translators: 1: title. */
					esc_html__('One thought on &ldquo;%1$s&rdquo;', 'wordkit'),
					'<span>' . get_the_title() . '</span>'
				);
			} else {
				printf( // WPCS: XSS OK.
					/* translators: 1: comment count number, 2: title. */
					esc_html(_nx('%1$s thought on &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', $wordkit_comment_count, 'comments title', 'wordkit')),
					number_format_i18n($wordkit_comment_count),
					'<span>' . get_the_title() . '</span>'
				);
			}
			?>
		</h4><!-- .uk-comments-title -->

		<?php the_comments_navigation(); ?>

		<?php
		function wordkit_list_comments($comment, $args, $depth)
		{
			if ('div' === $args['style']) {
				$tag       = 'div';
				$add_below = 'comment';
			} else {
				$tag       = 'li';
				$add_below = 'div-comment';
			}
		?>
			<<?php echo $tag ?> <?php comment_class(empty($args['has_children']) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
				<?php if ('div' != $args['style']) : ?>
					<article id="div-comment-<?php comment_ID() ?>" class="uk-comment">
					<?php endif; ?>
					<header class="uk-comment-header uk-grid-medium uk-flex-middle" uk-grid>
						<div class="uk-width-auto">
							<?php if ($args['avatar_size'] != 0) echo get_avatar($comment, $args['avatar_size']); ?>
						</div>
						<div class="uk-width-expand">
							<?php printf(__('<h4 class="uk-comment-title uk-margin-remove uk-link-reset">%s</h4>'), get_comment_author_link()); ?>
							<ul class="uk-comment-meta uk-subnav uk-subnav-divider uk-margin-remove-top">
								<li>
									<?php
									/* translators: 1: date, 2: time */
									printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time());
									?>
								</li>
								<li><?php comment_reply_link(array_merge($args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?></li>
							</ul>
						</div>

						<?php if ($comment->comment_approved == '0') : ?>
							<em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.'); ?></em>
							<br />
						<?php endif; ?>

						<div class="uk-link-heading"><a href="<?php echo htmlspecialchars(get_comment_link($comment->comment_ID)); ?>">
							</a><?php edit_comment_link(__('Edit'), '  ', '');
								?>
						</div>
					</header>
					<div class="uk-comment-body">
						<?php comment_text(); ?>
					</div>
					<?php if ('div' != $args['style']) : ?>
					</article>
				<?php endif; ?>
			<?php } ?>

			<ol class="uk-comment-list">
				<?php
				wp_list_comments(array(
					'callback'   => 'wordkit_list_comments',
				));
				?>
			</ol><!-- .uk-comment-list -->

			<?php
			the_comments_navigation();

			// If comments are closed and there are comments, let's leave a little note, shall we?
			if (!comments_open()) :
			?>
				<p class="no-comments"><?php esc_html_e('Comments are closed.', 'wordkit'); ?></p>
		<?php
			endif;

		endif; // Check for have_comments().

		comment_form(array(
			'fields' => array(
				'author' => sprintf(
					'<div class="uk-form-stacked uk-margin">%s %s</div>',
					sprintf(
						'<label class="uk-form-label" for="author">%s%s</label>',
						__('Name'),
						($req ? ' <span class="required">*</span>' : '')
					),
					sprintf(
						'<input class="uk-input" id="author" name="author" type="text" value="%s" size="30" maxlength="245"%s />',
						esc_attr($commenter['comment_author']),
						$html_req
					)
				),
				'email'  => sprintf(
					'<p class="uk-form-stacked uk-margin">%s %s</p>',
					sprintf(
						'<label class="uk-form-label" for="email">%s%s</label>',
						__('Email'),
						($req ? ' <span class="required">*</span>' : '')
					),
					sprintf(
						'<input class="uk-input" id="email" name="email" %s value="%s" size="30" maxlength="100" aria-describedby="email-notes"%s />',
						($html5 ? 'type="email"' : 'type="text"'),
						esc_attr($commenter['comment_author_email']),
						$html_req
					)
				),
				'url'    => sprintf(
					'<p class="uk-form-stacked uk-margin">%s %s</p>',
					sprintf(
						'<label class="uk-form-label" for="url">%s</label>',
						__('Website')
					),
					sprintf(
						'<input class="uk-input" id="url" name="url" %s value="%s" size="30" maxlength="200" />',
						($html5 ? 'type="url"' : 'type="text"'),
						esc_attr($commenter['comment_author_url'])
					)
				),
				'cookies' => '<div class="uk-margin"><label for="wp-comment-cookies-consent"><input class="uk-checkbox" id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox"
					value="yes"> ' . __('Save my name, email, and website in this browser for the next time I comment.') . ' </label></div>',
			),
			'comment_field' => '<div class="uk-form-stacked"><label class="uk-form-label" for="comment">' . _x('Comment', 'noun') . '</label><div class="uk-form-controls">
			<textarea class="uk-textarea" id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea></div></div>',
			'title_reply_before' => '<legend id="reply-title" class="uk-legend uk-margin">',
			'title_reply_after' => '</legend>',
			'cancel_reply_before'  => ' <small class="uk-button uk-button-text uk-link-reset">',
			'cancel_reply_after'   => '</small>',
			'class_submit' => 'uk-button uk-button-primary uk-margin',
			'logged_in_as'         => sprintf(
				'<div class="logged-in-as uk-link-heading uk-margin">%s</div>',
				sprintf(
					/* translators: 1: Edit user link, 2: Accessibility text, 3: User name, 4: Logout URL. */
					__('<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>'),
					get_edit_user_link(),
					/* translators: %s: User name. */
					esc_attr(sprintf(__('Logged in as %s. Edit your profile.'), $user_identity)),
					$user_identity,
					/** This filter is documented in wp-includes/link-template.php */
					wp_logout_url(apply_filters('the_permalink', get_permalink($post_id), $post_id))
				)
			),
		));
		?>

</div><!-- #comments -->